package com.alibaba.citrus.cr.mn.order.center.facade.function.common;

import com.epoch.app.mnordercenter.model.dto.OrderAtomBatchCloseRequest;
import com.epoch.app.mnordercenter.orderbaserequest.OrderAtomCloseRequest;
import com.epoch.app.mnordercenter.orderbaserequest.OrderAtomCloseResponse;
import com.epoch.app.mnordercenter.salesorderatom.dto.SapRefuseCallbackRequest;
import org.apache.commons.collections.CollectionUtils;

import java.util.Arrays;
import java.util.List;

/**
 * Chen.mu
 * 2023/5/12
 **/
public interface OrderAtomCloseService {
    /**
     * 批量关闭销售订单
     *
     * @param request
     */
    List<OrderAtomCloseResponse> batchClose(OrderAtomBatchCloseRequest request);

    /**
     * 关闭销售订单
     *
     * @param request
     */
    default OrderAtomCloseResponse close(OrderAtomCloseRequest request) {
        OrderAtomBatchCloseRequest orderAtomBatchCloseRequest = new OrderAtomBatchCloseRequest();
        orderAtomBatchCloseRequest.setBusinessType(request.getBusinessType());
        orderAtomBatchCloseRequest.setFromSys(request.getFromSys());
        orderAtomBatchCloseRequest.setBusinessUnitCode(request.getBusinessUnitCode());
        orderAtomBatchCloseRequest.setOrderList(Arrays.asList(request));
        List<OrderAtomCloseResponse> responseList = batchClose(orderAtomBatchCloseRequest);
        return CollectionUtils.isEmpty(responseList) ? null : responseList.get(0);
    }

    /**
     * 根据sap回调结果关闭销售订单
     *
     * @param request
     */
    void refuseCallback(SapRefuseCallbackRequest request);

    /**
     * 返回 销售 退货 换货 拼接错误信息用
     *
     * @return
     */
    String getOrderTagNameForErrorMsg();
}
